from torch.utils.data import TensorDataset

import torch

from torch.utils.data import DataLoader

a = torch.tensor(
    [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 2, 3],
     [4, 5, 6], [7, 8, 9], [1, 2, 3], [4, 5, 6], [7, 8, 9]])
print('a:\n', a)
b = torch.tensor([44, 55, 66, 44, 55, 66, 44, 55, 66, 44, 55, 66])

train_ids = TensorDataset(a, b)  # 相当于zip函数  a,b中元素的个数相同

# 切片输出

print('train_ids[0:1]:', train_ids[0:1])

print('=' * 60)

# 循环取数据

for x_train, y_label in train_ids:
    print(x_train, y_label)

# DataLoader进行数据封装

print('=' * 60)

train_loader = DataLoader(dataset=train_ids, batch_size=4, shuffle=False)  # shuffle参数：打乱数据顺序

for i, data in enumerate(train_loader, 1):  # 注意enumerate返回值有两个,一个是序号，一个是数据（包含训练数据和标签）,参数1是设置从1开始编号

    x_data, label = data

    print(' batch:{0} x_data:{1}  \n label: {2}'.format(i, x_data, label))

if __name__ == '__main__':
    a = torch.tensor([1, 2, 3])
    print('cross', torch.cross(a, a))
